﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace LeoQuestionaire
{
    public partial class Questionaire : Form
    {
        public Questionaire()
        {
            InitializeComponent();
        }

        void Save()
        {
            string path = "survey.csv";
            string header = "Name,Registration Number,Email,Company,Heard about Leonardo,Heard where,How easy was the Bird,Know any similar,Know other,Use designing, Use modeling,Use gaming,Use engineering,Use presenting,Use other,Recommend friend,Recommend company,Recommend other,Remarks";

            if (!File.Exists(path))
            {
                using (StreamWriter sw = File.CreateText(path))
                {
                    if (sw!=null)
                    sw.WriteLine(header);
                }
            }

            try
            {
                using (StreamWriter sw = File.AppendText(path))
                {
                    if (sw != null)
                    {
                        sw.Write("\"" + nameText.Text + "\",");
                        sw.Write("\"" + regNumberText.Text + "\",");
                        sw.Write("\"" + mailText.Text + "\",");
                        sw.Write("\"" + companyText.Text + "\",");

                        if (heardYes.Checked)
                        {
                            sw.Write("yes,");

                            if (heardFriend.Checked)
                                sw.Write("friend,");
                            else if (heardInternet.Checked)
                                sw.Write("internet,");
                            else if (heardCES.Checked)
                                sw.Write("CES,");
                            else if (heardOther.Checked)
                                sw.Write("\"" + heardOtherText.Text.Replace('\n',' ') + "\",");
                        }
                        else
                        {
                            sw.Write("no,,");
                        }

                        if (howEasy1.Checked) sw.Write("1,");
                        else if (howEasy2.Checked) sw.Write("2,");
                        else if (howEasy3.Checked) sw.Write("3,");
                        else if (howEasy4.Checked) sw.Write("4,");
                        else if (howEasy5.Checked) sw.Write("5,");
                        else sw.Write(",");

                        if (similarYes.Checked)
                        {
                            sw.Write("yes,");
                            sw.Write("\"" + similarYesText.Text.Replace('\n', ' ') + "\",");
                        }
                        else
                            sw.Write("no,,");

                        if (useDesigning.Checked)
                            sw.Write("yes,");
                        else
                            sw.Write(",");
                        if (useModeling.Checked)
                            sw.Write("yes,");
                        else
                            sw.Write(",");
                        if (useGaming.Checked)
                            sw.Write("yes,");
                        else
                            sw.Write(",");
                        if (useEngineering.Checked)
                            sw.Write("yes,");
                        else
                            sw.Write(",");
                        if (usePresenting.Checked)
                            sw.Write("yes,");
                        else
                            sw.Write(",");
                        if (useOther.Checked)
                            sw.Write("\"" + useOtherText.Text.Replace('\n', ' ') + "\",");
                        else
                            sw.Write(",");

                        if (recommendYes.Checked)
                        {
                            if (recommendFriend.Checked)
                                sw.Write("yes,");
                            else
                                sw.Write(",");
                            if (recommendCompany.Checked)
                                sw.Write("yes,");
                            else
                                sw.Write(",");
                            if (recommendOther.Checked)
                                sw.Write("\"" + recommendOtherText.Text.Replace('\n', ' ') + "\",");
                            else
                                sw.Write(",");
                        }
                        else
                            sw.Write(",,,");

                        sw.WriteLine("\"" + remarkText.Text.Replace('\n', ' ') + "\"");
                    }
                }
            }
            catch (Exception e)
            {

            }
        }

        private void okButton_Click(object sender, EventArgs e)
        {
            Save();
            Application.Exit();
        }

        private void similarYes_CheckedChanged(object sender, EventArgs e)
        {
            similarYesText.Enabled = similarYes.Checked;
        }

        private void heardOther_CheckedChanged(object sender, EventArgs e)
        {
            heardOtherText.Enabled = heardOther.Checked;
        }

        private void useOther_CheckedChanged(object sender, EventArgs e)
        {
            useOtherText.Enabled = useOther.Checked;
        }

        private void recommendOther_CheckedChanged(object sender, EventArgs e)
        {
            recommendOtherText.Enabled = recommendOther.Checked;
        }

        private void recommendYes_CheckedChanged(object sender, EventArgs e)
        {
            recommendYesGroup.Enabled = recommendYes.Checked;
        }

        private void groupBox7_Enter(object sender, EventArgs e)
        {

        }

        private void similarNo_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void heardYes_CheckedChanged(object sender, EventArgs e)
        {
            heardBox.Enabled = heardYes.Checked;
        }

    }
}
